package com.chx.mapper;

import com.chx.annotation.AutoFill;
import com.chx.entity.Roles;
import com.chx.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author cp-月入过万
 * @Date 2025/5/29
 */
@Mapper
public interface RoleMapper {

    @Select("select * from roles")
    List<Roles> getAllRoles();

    @AutoFill(OperationType.INSERT)
    @Insert("insert into roles(role_name,description,create_time,update_time) " +
            "values" +
            "(#{roleName},#{description},#{createTime},#{updateTime})")
    void insert(Roles roles);

    @AutoFill(OperationType.UPDATE)
    void update(Roles roles);

     @Delete("delete from roles where role_id = #{id}")
    void delete(Long id);

     @Select("select * from roles where role_id = #{id}")
    Roles getById(Long id);
     @Select("select count(*) from users where role_id = #{id}")
    int getUserCountByRoleId(Long id);
}
